package com.hnxxxy.common.Exception;

import com.hnxxxy.common.AjaxRtnEntity.AjaxRtnEntity;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @CLASSDESCRIPER:
 * @AUTHOR:suhui
 * @PHONE:13319575368
 * @EMIAL:13319575368@163.COM
 * @DATE: 2020/4/25
 * @PARAMDESCRIPER:
 * @OUTPARAMDESCRIPER:
 */
@ControllerAdvice
public class GlobExceptionHandler {

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public AjaxRtnEntity exceptionHandler(Exception ex){
        AjaxRtnEntity entity=new AjaxRtnEntity();
        if(ex instanceof UnauthorizedException){
            entity.setCode(AjaxRtnEntity.error);
            entity.setInfo("无令牌信息");
        }else if(ex instanceof AuthenticationException){
            entity.setCode(AjaxRtnEntity.error);
            entity.setInfo("用户信息有误请重新输入");
        }
        ex.printStackTrace();
        return entity;
    }
}
